package stage_1_module_3.code.homework_4;

import java.util.List;

public class Model {
    
    public static void showStudent(List<Student> sl) {
        System.out.println(sl);
    }

    public static void addStudent(List<Student> sl, Student a) {
        sl.add(a);
    }

    public static Student findStudentByNo(List<Student> sl, String no) {
        for (Student st : sl) {
            if (st.getNo().equals(no)) {
                return st;
            }
        }
        return null;
    }

    public static void removeStudentByNo(List<Student> sl, String no) {
        boolean hasFind = false;
        int i=0;
        for (Student st : sl) {
            if (st.getNo().equals(no)) {
                i = sl.indexOf(st);
                hasFind = true;
            }
        }
        if (hasFind) {
            sl.remove(i);
        }
    }

    public static void updateStudent(List<Student> sl, Student u) {
        for (Student st : sl) {
            if (st.getNo().equals(u.getNo())) {
                int i = sl.indexOf(st);
                sl.set(i, u);
                break;
            }
        }
    }
}
